package cn.cai;

import cn.cai.pojo.BasicInformation;
import cn.cai.service.BasicInformationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

@SpringBootApplication
@EnableScheduling
@Slf4j
public class AutomaticSafetyReportApplication {

    @Autowired
    private BasicInformationService basicInformationService;
    public static void main(String[] args) {
        SpringApplication.run(AutomaticSafetyReportApplication.class, args);
    }

    /**
     * 系统运行时，查询数据库中的数据，并创建单例
     * @return
     */
    @Bean(name = "generalTask")
    public ConcurrentLinkedQueue<BasicInformation> generalTask(){
        List<BasicInformation> all = basicInformationService.selectAll();
        log.info("任务从数据库加载进内存");
        return new ConcurrentLinkedQueue<>(all);
//        return list;
    }

}
